package tech.ezrealc.fall2023.repository.affair.classe;

import org.apache.ibatis.annotations.*;
import tech.ezrealc.fall2023.model.affair.classe.ClasseDO;

import java.math.BigInteger;
import java.util.List;

public interface ClasseRepository {

    @Select("select * from fall2023.affair_class;")
    List<ClasseDO> selectAll();

    @Insert("insert into fall2023.affair_class values " +
            "(#{id}, #{major}, #{name}, #{batch})")
    void insert(ClasseDO classeDO);

    @Select("select count(*) from fall2023.affair_class" +
            "    left join fall2023.enrollment_info on enrollment_info.classe = affair_class.id" +
            "    left join fall2023.affair_exam on affair_exam.classe = affair_class.id" +
            "    where (enrollment_info.classe = affair_class.id" +
            "       or affair_exam.classe = affair_class.id)" +
            "       and affair_class.id = #{id}")
    Integer checkRelated(@Param("id")BigInteger id);

    @Delete("delete from fall2023.affair_class where id = #{id}")
    void delete(@Param("id")BigInteger id);

    @Update("update fall2023.affair_class set " +
            "major = #{major}, name= #{name}, batch = #{batch} " +
            "where id = #{id}")
    void update(ClasseDO classeDO);

}
